/// 对比走的距离数据模型
class CompareDistanceData {
  final int steps;
  final int rate;
  final String sex;
  final int value1; // 0-3k
  final int value2; // 3k-6k
  final int value3; // 6k-9k
  final int value4; // 9k-12k
  final int value5; // 12k-15k
  final int value6; // 15k-18k
  final int value7; // 18k+

  CompareDistanceData({
    required this.steps,
    required this.rate,
    required this.sex,
    required this.value1,
    required this.value2,
    required this.value3,
    required this.value4,
    required this.value5,
    required this.value6,
    required this.value7,
  });

  factory CompareDistanceData.fromJson(Map<String, dynamic> json) {
    return CompareDistanceData(
      steps: json['steps'] ?? 0,
      rate: json['rate'] ?? 0,
      sex: json['sex'] ?? '男',
      value1: json['value1'] ?? 0,
      value2: json['value2'] ?? 0,
      value3: json['value3'] ?? 0,
      value4: json['value4'] ?? 0,
      value5: json['value5'] ?? 0,
      value6: json['value6'] ?? 0,
      value7: json['value7'] ?? 0,
    );
  }

  /// 获取所有区间的值列表
  List<int> get allValues => [value1, value2, value3, value4, value5, value6, value7];
}

/// 过去七天达成目标数据模型
class DailyTargetData {
  final String dailyValue; // 日期 "2025-10-16"
  final String week; // 星期 "周四"
  final int steps; // 步数
  final int duration; // 时长（分钟）
  final int calorie; // 卡路里
  final int stepCount; // 步数计数
  final int exerciseDuration; // 锻炼时长
  final int exerciseCalorie; // 锻炼卡路里

  DailyTargetData({
    required this.dailyValue,
    required this.week,
    required this.steps,
    required this.duration,
    required this.calorie,
    required this.stepCount,
    required this.exerciseDuration,
    required this.exerciseCalorie,
  });

  factory DailyTargetData.fromJson(Map<String, dynamic> json) {
    return DailyTargetData(
      dailyValue: json['dailyValue'] ?? '',
      week: json['week'] ?? '',
      steps: json['steps'] ?? 0,
      duration: json['duration'] ?? 0,
      calorie: json['calorie'] ?? 0,
      stepCount: json['stepCount'] ?? 0,
      exerciseDuration: json['exerciseDuration'] ?? 0,
      exerciseCalorie: json['exerciseCalorie'] ?? 0,
    );
  }

  /// 步数目标完成进度 (假设目标是8000步)
  double get stepsProgress => (steps / 8000).clamp(0.0, 1.0);

  /// 卡路里目标完成进度 (假设目标是400卡)
  double get caloriesProgress => (calorie / 400).clamp(0.0, 1.0);

  /// 时长目标完成进度 (假设目标是30分钟)
  double get timeProgress => (duration / 30).clamp(0.0, 1.0);

  /// 是否完成步数目标
  bool get isStepsCompleted => steps >= 8000;

  /// 是否完成卡路里目标
  bool get isCaloriesCompleted => calorie >= 400;

  /// 是否完成时长目标
  bool get isTimeCompleted => duration >= 30;

  /// 解析日期
  DateTime get date => DateTime.parse(dailyValue);
}
